﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using VideoCoreWCF;

namespace TranscoderService {
    partial class WindowCameraService : ServiceBase {
        public ServiceHost serviceHost = null;
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowCameraService"/> class.
        /// </summary>
        public WindowCameraService() {
            InitializeComponent();
            ServiceName = "WindowCameraService";
        }

        /// <summary>
        /// When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts.
        /// </summary>
        /// <param name="args">Data passed by the start command.</param>
        protected override void OnStart(string[] args) {
            if (serviceHost != null) {
                serviceHost.Close();
            }

            // Create a ServiceHost for the CalculatorService type and 
            // provide the base address.
            serviceHost = new ServiceHost(typeof(VideoCore));

            // Open the ServiceHostBase to create listeners and start 
            // listening for messages.
            serviceHost.Open();
        }

        /// <summary>
        /// When implemented in a derived class, executes when a Stop command is sent to the service by the Service Control Manager (SCM). Specifies actions to take when a service stops running.
        /// </summary>
        protected override void OnStop() {
            if (serviceHost != null) {
                serviceHost.Close();
                serviceHost = null;
            }
        }
    }
    /// <summary>
    /// 
    /// </summary>
    [RunInstaller(true)]
    public class ProjectInstaller : Installer {
        private ServiceProcessInstaller process;
        private ServiceInstaller service;

        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectInstaller"/> class.
        /// </summary>
        public ProjectInstaller() {
            process = new ServiceProcessInstaller();
            process.Account = ServiceAccount.LocalSystem;
            service = new ServiceInstaller();
            service.ServiceName = "WindowCameraService";
            Installers.Add(process);
            Installers.Add(service);
        }
    }
}
